<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>


<script type="text/javascript" src="<c:url value="/layout/javascript/tiny_mce/tiny_mce.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.form.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/form.js"/>">/**/</script>

<script type="text/javascript">
var subCatErrOpts = {
    msg : "<bean:message key="subcat.load.msg" bundle="errors"/>",
    boxTitle : "<bean:message key="subcat.load.boxTitle" bundle="errors"/>",
    msgStatus: "<bean:message key="subcat.load.msgStatus" bundle="errors"/>"
};

tinyMCE.init({
    mode : "exact",
    elements : "faqcontent",
    theme : "advanced",
    theme_advanced_buttons1 : "mybutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    plugins : 'inlinepopups',
    theme_advanced_resizing : true  
});

$(document).ready(function() {	
	var options = { 
            target:    '#validationbox',
            beforeSubmit: function() {
                             $('#validationbox').html('<img alt="<bean:message key="saving.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="saving.message"/>');
                             $('#validationbox').dialog('open');
                             /* Nell'attributo onsubmit del form viene richiamato il triggerSave()
                              * di tinyMCE. Mettendolo qui ci sono problemi con la sua invocazione e quindi
                              * al momento del submit si verificano errori di validazione sul contenuto
                              */
                          }, 
            error:     function () {
                           $('#validationbox').dialog('close');
                           showErrorDialog('#dialog', 
                                       { msg: "<bean:message key="faq.submit.form.msg" bundle="errors"/>",
                                         boxTitle: "<bean:message key="faq.submit.form.boxTitle" bundle="errors"/>",
                                         msgStatus: "<bean:message key="faq.submit.form.msgStatus" bundle="errors"/>" });
                       }  
    };
    
    $('#formFaq').ajaxForm(options);
    
	$("#category").change(function () {
        $('#Searchresult').empty();
        $('#Searchresult').html('<img alt="<bean:message key="wait.message" />" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="wait.message" />');
    	selectSubCategories($(this), '${pageContext.request.contextPath}/ticket/loadsubcategories.do', null, null);
    });
	
	 selectSubCategories($('#category'), '${pageContext.request.contextPath}/ticket/loadsubcategories.do', null, '${requestScope.faqform.subCategoryID}');
});
</script>

<div id="content">
		<!--FORM-->
		<fieldset id="fieldset">
			<legend class="fieldsetLabel"><bean:message key="faq.new" bundle="faq"/></legend>
			<div id="form_container">
				<html:form  styleId="formFaq" styleClass="appnitro" action="${requestScope.action}" onsubmit="tinyMCE.triggerSave();">
				    <html:hidden property="faqID"/>  
					<ul>
						<li id="li_5Operator" >
							<label class="description" for="categories"><bean:message key="faq.category" bundle="faq"/></label>
							<div>
								<html:select property="catID" styleClass="element select large" styleId="category"> 
									<html:options collection="category" property="categoryID" labelProperty="name"/>
								</html:select>
							</div>
						</li>		
						<li id="li_7Operator" >
							<label class="description" for="subCategories"><bean:message key="faq.subcategory" bundle="faq"/></label>
							<div>
                                <select  class="element select large" id="subCategories" name="subCategoryID">
                                </select>							    
							</div> 
						</li>   		
						<li id="li_1Operator" >
							<label class="description" for="subject"><bean:message key="faq.title" bundle="faq"/></label>
							<div>
								<html:text property="title" styleId="title" styleClass="element text large" maxlength="255" /> 
							</div> 
						</li>		
						<li id="li_2Operator" >
							<label class="description" for="detail"><bean:message key="faq.content" bundle="faq"/></label>
							<html:textarea property="faqcontent" style="width: 600px;" styleId="faqcontent"></html:textarea>	 
						</li>					
						<li class="buttons">
			    			<html:hidden property="faqID" value="" />
							<html:submit styleId="saveForm" styleClass="button_text">
								<bean:message key="button.save"/>
							</html:submit>
						</li>
					</ul>
    			</html:form>	
			</div>
		</fieldset>	
</div>		
		